package DataStructure.graph;

import DataStructure.linear.Stack;

public class TopoLogicalTest {
    public static void main(String[] args) {
        //准备有向图
        Digraph G = new Digraph(6);
        G.addEdge(0,2);
        G.addEdge(0,3);
        G.addEdge(1,3);
        G.addEdge(2,4);
        G.addEdge(3,4);
        G.addEdge(4,5);

        //通过TopoLogical对象对有向图的顶点进行排序
        TopoLogical topoLogical = new TopoLogical(G);

        Stack<Integer> order = topoLogical.order();
        //对顶点的线性序列进行打印
        StringBuilder sb = new StringBuilder();
        for (Integer w : order) {
            sb.append(w+"->");
        }
        String str = sb.toString();
        int index = str.lastIndexOf("->");
        str = str.substring(0, index);
        System.out.println(str);
    }
}
